﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Management;
using Infrastructure.Web.HealthMonitoring;

namespace Infrastructure.Web.WebModules
{
    public class SkynetHealthMonitoring : IHttpModule
    {

        
        

                

        public void Dispose()
        {
            

        }

        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(OnBeginRequest);
            context.EndRequest += new EventHandler(OnEndRequest);


        }
        public void OnBeginRequest(Object sender, EventArgs e)
        {
            HttpApplication httpApp = sender as HttpApplication;
            try
            {
                
                System.Int32 myCode = WebEventCodes.WebExtendedBase + 30;
                var swre = new SkynetWebRequestEvent("SkynetWebRequestEvent Start", this, myCode);                
                swre.Raise();
            }
            catch (Exception ex)
            {
                httpApp.Context.Response.Output.WriteLine(
                    ex.ToString());
            }

        }
        public void OnEndRequest(Object sender, EventArgs e)
        {
            HttpApplication httpApp = sender as HttpApplication;

            try
            {
                // Make sure to be outside the forbidden range.
                System.Int32 myCode = WebEventCodes.WebExtendedBase + 40;
                var swre = new SkynetWebRequestEvent("SkynetWebRequestEvent End", this, myCode);
                // Raise the event.
                swre.Raise();
            }
            catch (Exception ex)
            {
                httpApp.Context.Response.Output.WriteLine(
                    ex.ToString());
            }

        }

        
    }
}
